/**
 * 操作条
 */

let nextKey = 11
function add (vm) {
  var n = vm.list[Math.floor(Math.random() * vm.list.length)]
  vm.list = [{rank: nextKey++, title: n.title, desc: n.desc, elmHeight: 98}].concat(vm.list)
}

function changeSort (prop, vm) {
  vm.sortBy = prop
}

function HandleBar (h, vm) {
  return h('div.handleBar', [
    h('a.btn.add', {on: {click: [add, vm]}}, 'Add'),
    'Sort by: ',
    h('span.btn-group', [
      h('a.btn.rank', {class: {active: vm.sortBy === 'rank'}, on: {click: [changeSort, 'rank', vm]}}, 'Rank'),
      h('a.btn.title', {class: {active: vm.sortBy === 'title'}, on: {click: [changeSort, 'title', vm]}}, 'Title'),
      h('a.btn.desc', {class: {active: vm.sortBy === 'desc'}, on: {click: [changeSort, 'desc', vm]}}, 'Description'),
    ]),
  ])
}

export default HandleBar
